//这个文件为了不让index.js里面文件太冗余 把其中一些代码放到这儿
//引入一级路由组件

import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
//路由配置信息
export default[

    {
        path:"/paysuccess",
        component:PaySuccess,
        //路由元信息key不能瞎写，只能叫meta，里面带你想传的数据
        meta:{show:true},
        /* 只有从支付界面, 才能跳转到支付成功的界面 */
    beforeEnter (to, from, next) {
        if (from.path==='/pay') {
          next()
        } else {
          next('/pay')
        }
      }
    },
    {
        path:"/center",
        component:Center,
        //路由元信息key不能瞎写，只能叫meta，里面带你想传的数据
        meta:{show:true},
        //二级路由组件
        children: [
            {
              // path: '/center/myorder',
              path: 'myorder',
              component: MyOrder,
            },
            {
              path: 'grouporder',
              component: GroupOrder,
            },
            {//路由重定向
              path: '/center',
              redirect:'/center/myorder'
            },

      
          ]
    },
    
    {
        path:"/home",
        component:()=>import("@/pages/Home"),
        //路由元信息key不能瞎写，只能叫meta，里面带你想传的数据
        meta:{show:true}
    },
    {
        path:"/pay",
        component:Pay,
        //路由元信息key不能瞎写，只能叫meta，里面带你想传的数据
        meta:{show:true},
        /* 只能从交易界面, 才能跳转到支付界面 */
    beforeEnter (to, from, next) {
        if (from.path==='/trade') {
          next()
        } else {
          next('/trade')
        }
      }
    },
    {
        path:"/trade",
        component:Trade,
        //路由元信息key不能瞎写，只能叫meta，里面带你想传的数据
        meta:{show:true},
        /* 只能从购物车界面, 才能跳转到交易界面 */
    beforeEnter (to, from, next) {
        if (from.path==='/shopcart') {
          next()
        } else {
          next('/shopcart')
        }
      }
    },
    {
        path:"/shopcart",
        component:ShopCart,
        
        meta:{show:true}
    },
    {
        path:"/addcartsuccess",
        name:'addcartsuccess',
        component:AddCartSuccess,
        
        meta:{show:true}
    },
    {
        path:"/search/:keyword",
        component:Search,
        meta:{show:true},
        name:"search"
    },
    {
        path:"/login",
        component:Login,
        meta:{show:false}
    },
    {
        path:"/register",
        component:Register,
        meta:{show:false}
    },
    {
        path:"/detail/:skuid",
        component:Detail,
        meta:{show:true}

    },
    {//重定向，项目跑起来的时候，访问？立马定向到首页
        path:"*",
        redirect:"/home"

    }

]
